let Mock = require('mockjs');

// node app.js 要求db.js 暴露一个object

// 商品详情图片
let imgs = (n) => {
    let data = [];
    for (let i = 0; i < n; i++) {
        data.push(Mock.Random.image('400x300', Mock.Random.color(), Mock.Random.cword(1)));
    }
    return data;
}
// 商品表
let goodDate = (n) => {
    let data = [];
    for (let i = 1; i <= n; i++) {
        data.push({
            _id: i + '', // 商品id
            id: i + '',
            gname: '@ctitle(8,10)', // 商品名称
            gdesc: '@ctitle(8,15)', // 商品描述
            gcate_id: '@natural(1,10)', // 商品分类id
            price: '@natural(0, 1000)', // 价格
            gimg: Mock.Random.image('450x300', Mock.Random.color(), Mock.Random.cword(1)),
            detail: imgs(10),
            stock: '@natural(0, 1000)', // 库存
            status: '@natural(0, 1)', // 商品状态
            time: '@now()',
            shopname: '@cword(4,7)'
        })
    }
    return data;
};

//商品类别表
let cateNav = [{
        id: 1,
        title: '酒水食品'
    },
    {
        id: 2,
        title: '电脑办公'
    },
    {
        id: 3,
        title: '服装服饰'
    },
    {
        id: 4,
        title: '衣帽鞋包'
    },
    {
        id: 5,
        title: '运动户外'
    },
    {
        id: 6,
        title: '汽车用品'
    },
    {
        id: 7,
        title: '母婴玩具'
    },
    {
        id: 8,
        title: '医药保健'
    },
    {
        id: 9,
        title: '图书音像'
    },
    {
        id: 10,
        title: '旅游生活'
    }
];

let goodCate = (n) => {
    let data = [];
    for (let i = 1; i <= n; i++) {
        data.push({
            _id: i + '',
            id: i + '',
            cname: '@ctitle(4)', // 分类名称
            time: '@now()'
        })
    }
    return data;
};

// 购物车表
let goodCart = (n) => {
    let data = [];
    for (let i = 1; i <= n; i++) {
        data.push({
            id: i + '',
            user_id: 1 + '',
            good_id: i+'',
            num: '@natural(0, 20)', // 商品数量
            time: '@now()'
        })
    }
    return data;
};

// 导航
let nav = () => {
    let data = [];
    for (let i = 1; i <= 10; i++) {
        data.push({
            title: '@cword(4)',
            bgColor: '@hex'
        })
    }
    return data;
}
module.exports = Mock.mock({
    "user": {
        "username": Mock.Random.cname(), // 用户名
        "password": '123456', // 密码
        "sex": Mock.Random.boolean() ? '男' : '女', // 性别
        "age": Mock.Random.integer(0, 100), // 年龄
        "email": Mock.Random.email(), // 邮箱
        "address": Mock.Random.county(true), // 地址
        "phone": /[1]([3-9])[0-9]{9}/,
        "icon": Mock.Random.image('400x400', Mock.Random.color(), Mock.Random.cword(1)),
        "time": Mock.Random.now()
    },
    "goods": goodDate(30),
    "carts": goodCart(10),
    "cate": cateNav,
    "nav": nav(),

})